package model

import (
	"encoding/json"
	"fmt"
	"os"
)

type Config struct {
	ScreenWidth     int     `json:"screenWidth"`
	ScreenHeight    int     `json:"screenHeight"`
	SpeedFactor     int     `json:"speedFactor"`
	BgSpeedFactor   int     `json:"bgSpeedFactor"`
	JumpSpeedFactor int     `json:"jumpSpeedFactor"`
	Gravity         float64 `json:"gravity"` //用来模拟重力,用于玩家的下落
	Nums            int     `json:"nums"`

	BulletWidth       int     `json:"bulletWidth"`
	BulletHeight      int     `json:"bulletHeight"`
	BulletSpeedFactor float64 `json:"bulletSpeedFactor"`
	MaxBulletNum      int     `json:"maxBulletNum"`
	BulletInterval    int64   `json:"bulletInterval"`
	MaxCoins          int     `json:"maxCoins"`

	FontSize int `json:"fontSize"`
}

func LoadConfig() *Config {
	file, err := os.Open("static/config.json")
	if err != nil {
		fmt.Println("配置文件无法打开")
		panic(err)
	}
	var cfg *Config
	err = json.NewDecoder(file).Decode(&cfg)
	if err != nil {
		fmt.Println("配置文件解析无法打开")
		panic(err)
	}
	return cfg
}
